///////////////////////////////////////////////////////////////////////////////
//
//  Copyright (C) 2007-2009 ILOG, S.A.
//  All Rights Reserved.
//  The following is ILOG Source Code.  No modifications may be made to the  
//  ILOG Source Code.  Any usage of the ILOG Source Code is subject to 
//  the terms and conditions of the ILOG End User License Agreement   
//  applicable to this ILOG software product.
//
///////////////////////////////////////////////////////////////////////////////

package ilog.gauges
{
  import flash.geom.Rectangle;
  
  import ilog.gauges.gaugesClasses.TickRendererBase;
  import ilog.utils.CSSUtil;
  
  import mx.graphics.IFill;
  import mx.graphics.IStroke;
  import mx.graphics.SolidColor;  

  /**
   * This class is a simple <code>IDataRenderer</code> implementation used to render ticks 
   * on a scale. It renders ticks in the form of circles. 
   * If they are available it uses the <code>fill</code> and <code>stroke</code> style properties 
   * of its associated scale renderer <code>majorTickStyleName</code> or 
   * <code>minorTickStyleName</code>. 
   * If they are not available it uses the regular <code>fill</code> and <code>stroke</code>
   * properties.  
   *  
   * @mxml
   *  
   * <p>The <code>&lt;ilog:CircleTickRenderer&gt;</code> tag inherits all the properties
   * of its parent classes and adds the following properties:</p>
   *
   * <pre>
   * &lt;ilog:<i>CircleTickRenderer</i>
   *   <strong>Properties</strong>
   *   fill="<i>0x555555</i>"
   *   stroke="null"
   * /&gt;
   * </pre>
   * 
   * @see ilog.gauges.circular.renderers.CircularScaleRenderer
   * @see ilog.gauges.rectangular.renderers.RectangularScaleRenderer
   * @ilog.reviewed SH April 24 08
   */
  public class CircleTickRenderer extends TickRendererBase 
  {   
    /**
     * Constructor.
     */
    public function CircleTickRenderer()
    {
      super();
    }
    
    private var _stroke:IStroke;
    
    [Inspectable(defaultValue=null, type="mx.graphics.IStroke",category="Style")]
    
    /**
     * Specifies the characteristics of the stroke for the ticks.
     * This style property must reference an instance of an <code>IStroke</code> implementation.
     * If the value is <code>null</code>, no stroke is drawn.  
     * 
     * @default null
     */
    public function get stroke():IStroke
    {
      return _stroke;
    }
    
    /**
     * @private
     */
    public function set stroke(value:IStroke):void
    {
      _stroke = value;
      invalidateDisplayList();
    }    
    
    private var _fill:IFill = new SolidColor(0x555555);
    
    [Inspectable(type="mx.graphics.IFill",category="Style")]
    
    /**
     * Specifies the fill for the ticks.
     * This style property must reference an instance of an <code>IFill</code> implementation.  
     * 
     * @default 0x555555
     */
    public function get fill():IFill
    {
      return _fill;
    }
    
    /**
     * @private
     */
    public function set fill(value:IFill):void
    {
      _fill = value;
      invalidateDisplayList();
    }       

    /**
     * Draws the tick.
     *
     * @param unscaledWidth Specifies the width of the component, in pixels,
     * in the component's coordinates, regardless of the value of the
     * <code>scaleX</code> property of the component.
     *
     * @param unscaledHeight Specifies the height of the component, in pixels,
     * in the component's coordinates, regardless of the value of the
     * <code>scaleY</code> property of the component. 
     */
    protected override function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
    {
      graphics.clear();
      
      var f:IFill;
      if (styleName != null && getStyle("fill") != undefined) {
        f = CSSUtil.fillFromStyle(getStyle("fill"));
      } else if (fill) {
        f = fill;
      }
      if (f)
        f.begin(graphics, new Rectangle((width - unscaledWidth) / 2, 
                                        (height - unscaledHeight) / 2, 
                                        unscaledWidth, unscaledHeight));
                                        
      if (styleName != null && getStyle("stroke") != undefined) {
        getStyle("stroke").apply(graphics);
      } else if (stroke) {
        stroke.apply(graphics);        
      }                                  

      graphics.drawCircle(width / 2, height / 2, Math.min(unscaledWidth, unscaledHeight) / 2); 
      
      if (f)
        f.end(graphics);
    }      
  }
}
